#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
 
struct Person {
    string first, last;
 
    Person(string f, string l)
    {
        first = f;
        last = l;
    }
 
    bool operator==(const Person& p) const
    {
        return first == p.first && last == p.last;
    }
};
 
class MyHashFunction {
public:
 
    // We use predefined hash functions of strings
    // and define our hash function as XOR of the
    // hash values.
    size_t operator()(const Person& p) const
    {
        return (hash<string>()(p.first)) ^
               (hash<string>()(p.last));
    }
};

struct TestHash
{
    size_t operator()(const Person &rvalue) const   //注意这里有两个const 修饰
    {
        return (hash<string>()(rvalue.first)) ^
               (hash<string>()(rvalue.last));
    }
};





// Driver code
int main()
{
  //  unordered_map<Person, int, MyHashFunction> um;
    unordered_map<Person, int, TestHash> um;
    Person p1("kartik", "kapoor");
    Person p2("Ram", "Singh");
    Person p3("Laxman", "Prasad");
 
    um[p1] = 100;
    um[p2] = 200;
    um[p3] = 100;
 
    for (auto e : um) {
        cout << "[" << e.first.first << ", "
             << e.first.last
             << "] = > " << e.second << '\n';
    }
    return 0;
}
